package com.example.controller;

import com.example.statemachine.ApplicationRequest;
import com.example.statemachine.ApplicationStateMachine;
import com.example.statemachine.StatesEvents;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@AllArgsConstructor
@Slf4j
public class EventController {
    private ApplicationStateMachine applicationStateMachine;

    @PostMapping("/event")
    public EventResponse testStateMachine(@RequestBody EventRequest eventRequest) {
        log.info("eventRequest=> {}", eventRequest);
        ApplicationRequest applicationRequest = ApplicationRequest.builder()
                .applicationId(eventRequest.getApplicationId())
                .build();
        return applicationStateMachine.sentEvent(StatesEvents.State.valueOf(eventRequest.getState()),
                eventRequest.getEvent(), applicationRequest);
    }
}
